<template>
  <div class="index">
    <head-text titleText="专利审核"></head-text>
    <div class="list-content">
      <div class="filter-area">
        <Search :searchData="searchData" :searchItem="searchItem"></Search>
      </div>
      <div class="table-title">
        <span></span>
        <h5>专利列表</h5>
      </div>
      <custom-table
        :tableData="tableData"
        :tableListData="tableListData"
        :tableBtn="tableBtn"
        :currentData="currentData"
        @onPageChange="onPageChange"
        @onSizeChange="onSizeChange"
        @handleEdit="handleEdit"
        @handleViewOther="handleViewOther"
        v-if="pageReset"
      ></custom-table>
    </div>
    <dialog-com :dialogObj="dialogObj" @reflash="getList"></dialog-com>
  </div>
</template>
<script>
import customTable from "@c/table";
import Search from "@c/search";
import headText from "@c/headText";
import dialogCom from "./dialogCom";
import {
  getPatentManagePageApi,
  getCustomerListApi,
  updatePatentManageApi
} from "@s/api";
import { MANAGESTATUS, MANAGESTATUSLIST } from "@u/wordbook";
export default {
  name: "index",
  data() {
    return {
      nowPage: 1,
      total: 0,
      limit: 10,
      pageReset: true,
      searchItem: [],
      searchData: {
        customerId: "",
        title: "",
        applicationNumber: "",
        startTime: "",
        endTime: "",
        isNeedPay: "",
        status: ""
      },
      parameter: {
        id: "",
        status: ""
      },
      dialogObj: {
        id: "",
        title: "",
        show: false,
        form: {
          title: "",
          type: ""
        }
      },
      dialogPayObj: {
        id: "",
        title: "",
        show: false,
        form: {
          title: "",
          type: ""
        }
      },
      tableData: [],
      customerSelect: [],
      currentData: {},
      manageStatusList: MANAGESTATUSLIST
    };
  },
  components: {
    headText,
    dialogCom,
    Search,
    customTable
  },
  created() {
    // form搜索
    this.searchItem = [
      {
        type: "select",
        label: "客户名称：",
        prop: "customerId",
        placeholder: "请选择",
        selectList: this.customerSelect
      },
      {
        type: "input",
        label: "专利名",
        prop: "title",
        placeholder: "请输入专利名"
      },
      {
        type: "daterange",
        label: "申请日：",
        timeFormat: "yyyy-MM-dd",
        timeList: ["startTime", "endTime"]
      },
      {
        type: "select",
        label: "状态：",
        prop: "status",
        placeholder: "请选择",
        selectList: this.manageStatusList
      }
    ];
    //  table表格
    this.tableListData = [
      { width: "50", label: "", type: "index" },
      { prop: "customerName", width: "", label: "客户名称", type: "a" },
      { prop: "title", width: "150px", label: "专利名", type: "a" },
      { prop: "applicationNumber", width: "", label: "申请号", type: "a" },
      { prop: "applicationDatetime", width: "", label: "申请日期", type: "a" },
      { prop: "applicant", width: "", label: "申请人", type: "a" },
      {
        prop: "status",
        width: "",
        label: "状态",
        type: "wordbook",
        wordbookList: this.manageStatus
      },
      { label: "操作", type: "btn", width: "80", fixed: "right" }
    ];
    // 按钮
    this.tableBtn = [
      {
        name: "审核",
        btnType: "primary",
        handleFn: "handleEdit",
        type: "isShow",
        isShowStatus: "status",
        isShowValue: "0"
      },
      {
        name: "审核",
        btnType: "primary",
        handleFn: "handleEdit",
        type: "isShow",
        isShowStatus: "status",
        isShowValue: "1"
      }
    ];
  },
  mounted() {
    this.getCustomerSelect();
    this.getList();
  },
  methods: {
    // 过滤
    manageStatus(val) {
      return MANAGESTATUS[val];
    },
    // 查看
    handleViewOther(row) {
      this.dialogObj.id = row.id;
      this.dialogObj.read = true;
      this.dialogObj.show = true;
      this.dialogObj.title = "查看专利";
      this.dialogObj.form = row;
    },
    // 审核
    handleEdit(row) {
      if (row.status == "0") {
        this.$confirm("点击确认后进行审核，客户将无法修改此专利信息?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.parameter.id = row.id;
          this.parameter.status = "1";
          let json = JSON.parse(JSON.stringify(this.parameter));
          updatePatentManageApi(json).then(() => {
            this.getList();
            this.dialogObj.id = row.id;
            this.dialogObj.read = false;
            this.dialogObj.show = true;
            this.dialogObj.form = row;
            this.dialogObj.title = "审核专利";
          });
        });
      } else {
        this.dialogObj.id = row.id;
        this.dialogObj.read = false;
        this.dialogObj.show = true;
        this.dialogObj.form = row;
        this.dialogObj.title = "审核专利";
      }
    },
    onPageChange(val) {
      this.nowPage = val;
      this.getList();
    },
    onSizeChange(val) {
      this.nowPage = 1;
      this.limit = val;
      this.getList();
    },
    // 搜索事件
    getDataList(val) {
      this.searchData = val;
      this.nowPage = 1;
      this.limit = 10;
      this.pageReset = false;
      this.$nextTick(() => {
        this.getList();
        this.pageReset = true;
      });
    },
    //获取列表
    getList() {
      let json = JSON.parse(JSON.stringify(this.searchData));
      json.page = this.nowPage;
      json.limit = this.limit;
      getPatentManagePageApi(json).then(res => {
        this.tableData = res.list;
        this.currentData.total = res.total;
      });
    },
    // 获取客户列表
    getCustomerSelect() {
      getCustomerListApi().then(res => {
        let newCustomerList = [];
        res.forEach(item => {
          var newItem = {
            id: item.id,
            value: item.customerName
          };
          newCustomerList.push(newItem);
        });
        this.customerSelect = newCustomerList;
        this.searchItem.forEach(item => {
          if (item.prop == "customerId") {
            item.selectList = this.customerSelect;
          }
        });
      });
    }
  }
};
</script>
<style scoped lang="scss"></style>
